package tenantchannellogic

import (
	"context"
	model "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/tenant/channel"
	schema "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/schema/tenant/channel"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/pkg/xerrors"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type KbzpayUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewKbzpayUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *KbzpayUpdateLogic {
	return &KbzpayUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *KbzpayUpdateLogic) KbzpayUpdate(in *rpc.KbzpayUpdateRequest) (*rpc.KbzpayUpdateResponse, error) {
	var (
		CommonResp rpc.CommonResp
		kbzpay     schema.TenantChannelKbzpay
	)

	kbzpayModel := model.NewTenantChannelKbzpayModel(l.ctx, l.svcCtx.Db)

	kbzpay.Code = in.Code
	kbzpay.Phone = in.Phone
	kbzpay.CardHolder = in.CardHolder
	kbzpay.MinAmount = in.MinAmount
	kbzpay.MaxAmount = in.MaxAmount
	kbzpay.DailyTimes = in.DailyTimes
	kbzpay.DailyAmount = in.DailyAmount
	kbzpay.RemainTimes = in.RemainTimes
	kbzpay.RemainAmount = in.RemainAmount
	kbzpay.VisionLevel = in.VisionLevel
	kbzpay.IsDisplay = in.IsDisplay
	kbzpay.Sort = in.Sort
	kbzpay.ID = in.Id
	err := kbzpayModel.UpdateKbzpay(&kbzpay)
	if err != nil {
		CommonResp.Code = xerrors.DBError
		CommonResp.Message = "Database operation error"
		return &rpc.KbzpayUpdateResponse{
			CommonResp: &CommonResp,
		}, err
	}

	CommonResp.Message = "Success"
	return &rpc.KbzpayUpdateResponse{
		CommonResp: &CommonResp,
	}, nil
}
